package cn.stylefeng.guns.modular.manager.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.FlowAbout;
import cn.stylefeng.guns.modular.manager.mapper.FlowAboutMapper;
import cn.stylefeng.guns.modular.manager.model.params.FlowAboutParam;
import cn.stylefeng.guns.modular.manager.model.result.FlowAboutResult;
import  cn.stylefeng.guns.modular.manager.service.FlowAboutService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 关于公司 服务实现类
 * </p>
 *
 * @author yumker
 * @since 2021-01-07
 */
@Service
public class FlowAboutServiceImpl extends ServiceImpl<FlowAboutMapper, FlowAbout> implements FlowAboutService {

    @Override
    public void add(FlowAboutParam param){
        FlowAbout entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FlowAboutParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FlowAboutParam param){
        FlowAbout oldEntity = getOldEntity(param);
        FlowAbout newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FlowAboutResult findBySpec(FlowAboutParam param){
        return null;
    }

    @Override
    public List<FlowAboutResult> findListBySpec(FlowAboutParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FlowAboutParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FlowAboutParam param){
        return param.getAboutId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FlowAbout getOldEntity(FlowAboutParam param) {
        return this.getById(getKey(param));
    }

    private FlowAbout getEntity(FlowAboutParam param) {
        FlowAbout entity = new FlowAbout();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
